/**
 *  Copyright 2009 Henning Teek, Ingo Renner
 *  
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *  
 *  http://www.apache.org/licenses/LICENSE-2.0
 *  
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License. 
 */
package com.googlecode.bricket.web.common.forms;

import org.apache.wicket.Application;
import org.apache.wicket.Component;
import org.apache.wicket.Resource;
import org.apache.wicket.SharedResources;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.model.IModel;

import com.googlecode.bricket.web.WicketApplication;
import com.googlecode.bricket.web.common.IconFactory;
import com.googlecode.bricket.web.common.brix.BrixFileNodeResource;

/**
 * @author Ingo Renner
 * @author Henning Teek
 */
public class ShinyForm<T> extends Form<T> {
	final IVisitor<Component> shinyVisitor = new ShinyFormVisitor(allowShinyOnAjaxRequest());
	
	public ShinyForm(String id, IModel<T> model) {
		super(id, model);
	}

	public ShinyForm(String id) {
		super(id);
		
	}

	public void onBeforeRender() {
		super.onBeforeRender();
		// make sure that the icon for the RequiredBorder is registered
		SharedResources sr = getApplication().getSharedResources();
		if (null == sr.get(Application.class, RequiredBorder.ICON_NAME, null, null, false)) {
			Resource icon = new BrixFileNodeResource(IconFactory.createStarSmallIconReference().getName(),
					(WicketApplication) getApplication());
			sr.add(RequiredBorder.ICON_NAME, icon);
		}
		
		visitChildren(shinyVisitor);
	}
	
	protected boolean allowShinyOnAjaxRequest() {
		return false;
	}
}
